package com.itheima.service.Impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    public List<Dept> findAll() {
        return deptMapper.findAll();

    }

    public int deleteById(int id) {
        return deptMapper.deleteById(id);
    }

    public int insertData(Dept dept) {
        //1.补全基础数据

        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //2.调用dao
        return deptMapper.insertData(dept);
    }

    public Dept findById(int id) {
        return deptMapper.findById(id);
    }

    public void update(Dept dept) {

        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.update(dept);
    }
}
